<template>
  <div>
    <basic-container shadow="hover">
      <curd-title :title="'基本信息'" />
      <avue-form ref="form" :option="option" v-model="form">
        <template slot="typeCode">
          <el-input class="pointer" v-model="form.typeCode" @focus="selectSupplier" placeholder="请选择" readonly>
            <i slot="suffix" class="el-icon-search"></i>
          </el-input>
        </template>
        <template slot="comprehensiveRiskLevel">
          <el-tag :type="['primary', 'danger', 'warning', 'success'][form.comprehensiveRiskLevel]">
            <!-- {{ scope.row.riskLevel_dictText }} -->
            {{ ['Y', 'R', 'A', 'G'][form.comprehensiveRiskLevel] }}
          </el-tag>
        </template>
      </avue-form>
    </basic-container>
    <measures v-if="['edit','view'].includes(type)"/>
  </div>
</template>

<script>
import CurdTitle from '@/components/base/title'
import { option, supplierOption } from '@/option/tenant/supplier/risk-form'
import measures from '@/views/tenant/supplier/risk/components/measures'
export default {
  name: 'riskForm',
  props: ['type'],
  provide() {
    return {
      type: this.type
    }
  },
  components: { CurdTitle, measures },
  data() {
    return {
      form: {},
      option: option.call(this)
    }
  },
  computed: {
    getRiskLevel() {
      return {
        p: this.form.possibility,
        r: this.form.riskResult
      }
    }
  },
  watch: {
    getRiskLevel(val) {
      if (val.p === '0') {
        if (val.r === '0') return (this.form.comprehensiveRiskLevel = '3')
        if (val.r === '1') return (this.form.comprehensiveRiskLevel = '3')
        if (val.r === '2') return (this.form.comprehensiveRiskLevel = '0')
        if (val.r === '3') return (this.form.comprehensiveRiskLevel = '0')
        if (val.r === '4') return (this.form.comprehensiveRiskLevel = '2')
      }
      if (val.p === '1') {
        if (val.r === '0') return (this.form.comprehensiveRiskLevel = '3')
        if (val.r === '1') return (this.form.comprehensiveRiskLevel = '0')
        if (val.r === '2') return (this.form.comprehensiveRiskLevel = '0')
        if (val.r === '3') return (this.form.comprehensiveRiskLevel = '2')
        if (val.r === '4') return (this.form.comprehensiveRiskLevel = '2')
      }
      if (val.p === '2') {
        if (val.r === '0') return (this.form.comprehensiveRiskLevel = '0')
        if (val.r === '1') return (this.form.comprehensiveRiskLevel = '0')
        if (val.r === '2') return (this.form.comprehensiveRiskLevel = '2')
        if (val.r === '3') return (this.form.comprehensiveRiskLevel = '2')
        if (val.r === '4') return (this.form.comprehensiveRiskLevel = '1')
      }
      if (val.p === '3') {
        if (val.r === '0') return (this.form.comprehensiveRiskLevel = '0')
        if (val.r === '1') return (this.form.comprehensiveRiskLevel = '2')
        if (val.r === '2') return (this.form.comprehensiveRiskLevel = '2')
        if (val.r === '3') return (this.form.comprehensiveRiskLevel = '1')
        if (val.r === '4') return (this.form.comprehensiveRiskLevel = '1')
      }
      if (val.p === '4') {
        if (val.r === '0') return (this.form.comprehensiveRiskLevel = '2')
        if (val.r === '1') return (this.form.comprehensiveRiskLevel = '2')
        if (val.r === '2') return (this.form.comprehensiveRiskLevel = '1')
        if (val.r === '3') return (this.form.comprehensiveRiskLevel = '1')
        if (val.r === '4') return (this.form.comprehensiveRiskLevel = '1')
      }
    }
  },
  methods: {
    selectSupplier() {
      this.$quickModal({
        title: '选择供应商',
        width: '80%',
        componentIsTag: true,
        component: 'suppliers',
        props: {
          multiple: false,
          columns: supplierOption
        },
        on: {
          change: row => {
            console.log(row)
          }
        }
      })
    }
  }
}
</script>

<style></style>
